
/*
 * @userName: 湫之恋
 * @Author: Seven
 * @Date: 2020-07-02 15:39:09
 * @LastEditors: Seven
 * @LastEditTime: 2020-07-02 18:00:19
 */
// var fs = require("fs");
//获取全部车辆
const mongoose = require('mongoose')
module.exports.getCarAll=async function ({several,yeshu}){
    //计算总条数
    let rowss=await mongoose.model('carModel').countDocuments();
    //计算最大页数
    const pages=Math.ceil(rowss/several);
    //获取车辆数据
    let data= await mongoose.model('carModel').find().populate("userId").limit(several - 0).skip((yeshu - 1) * several);
     return { data, rowss, pages, several, yeshu }
}
//查询车辆
module.exports.chaCar=async function ({several,yeshu,lei,leirong}){
    //console.log('第三层',{lei,leirong})
    
    //计算总条数
    let rowss=await mongoose.model('carModel').countDocuments();
    //计算最大页数
    const pages=Math.ceil(rowss/several);
    //获取车辆数据
    let data= await mongoose.model('carModel').find({ [lei]: leirong }).populate("userId").limit(several - 0).skip((yeshu - 1) * several);
    return { data, rowss, pages, several, yeshu }
}
//获取待审核车辆
module.exports.getCaraudit=async function ({several,yeshu,audit}){
    //计算总条数
    let rowss=await mongoose.model('carModel').countDocuments();
    //计算最大页数
    const pages=Math.ceil(rowss/several);
    //获取车辆数据
    let data= await mongoose.model('carModel').find({carBool:audit}).populate("userId").limit(several - 0).skip((yeshu - 1) * several);
    return { data, rowss, pages, several, yeshu }
}
//查询待审核车辆
module.exports.chaCaraudit=async function ({several,yeshu,lei,leirong,audit}){
    //计算总条数
    let rowss=await mongoose.model('carModel').countDocuments();
    //计算最大页数
    const pages=Math.ceil(rowss/several);
    //获取车辆数据
    let data= await mongoose.model('carModel').find({ [lei]: leirong, carBool:audit}).populate("userId").limit(several - 0).skip((yeshu - 1) * several);
    return { data, rowss, pages, several, yeshu }
}
//车辆审核通过
module.exports.passcar=async function({_id,carBool}){
    
    let data= await mongoose.model('carModel').updateOne({_id},{carBool:carBool})
    console.log('第三层要改的车',data)
}
//车辆审核不通过
module.exports.nopasscar=async function({_id,carBool}){
    let data= await mongoose.model('carModel').updateOne({_id},{carBool:carBool})
}
